﻿using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Xms.Abp.Application.Dtos;
using Xms.Abp.Application.Services;

namespace Xms.Abp.AspNetCore.Mvc;

public abstract class XmsReadOnlyController<TService, TEntityDto, TKey>
    : XmsReadOnlyController<TService, TEntityDto, TKey, PagedSortedAndFilterParameter>,
    IXmsReadOnlyAppService<TEntityDto, TKey>
    where TService : IXmsReadOnlyAppService<TEntityDto, TKey>
    where TEntityDto : IEntityDto<TKey>
{
}
public abstract class XmsReadOnlyController<TService, TEntityDto, TKey, TPagedParameter>
    : XmsReadOnlyController<TService, TEntityDto, TEntityDto, TKey, TPagedParameter>,
    IXmsReadOnlyAppService<TEntityDto, TKey, TPagedParameter>
    where TService : IXmsReadOnlyAppService<TEntityDto, TKey, TPagedParameter>
    where TEntityDto : IEntityDto<TKey>
    where TPagedParameter : class, IPagedSortedAndFilterParameter
{
}
public abstract class XmsReadOnlyController<TService, TDetailsResult, TPagingListResult, TKey, TPagedParameter>
    : XmsReadOnlyController<TService, TDetailsResult, TPagingListResult, TDetailsResult, TKey, TPagedParameter>,
    IXmsReadOnlyAppService<TDetailsResult, TPagingListResult, TDetailsResult, TKey, TPagedParameter>
    where TService : IXmsReadOnlyAppService<TDetailsResult, TPagingListResult, TKey, TPagedParameter>
    where TDetailsResult : IEntityDto<TKey>
    where TPagingListResult : IEntityDto<TKey>
    where TPagedParameter : class, IPagedSortedAndFilterParameter
{
}
public abstract class XmsReadOnlyController<TService, TDetailsResult, TPagingListResult, TExportResult, TKey, TPagedParameter> : XmsController<TService>,
    IXmsReadOnlyAppService<TDetailsResult, TPagingListResult, TExportResult, TKey, TPagedParameter>
    where TService : IXmsReadOnlyAppService<TDetailsResult, TPagingListResult, TKey, TPagedParameter>
    where TDetailsResult : IEntityDto<TKey>
    where TPagingListResult : IEntityDto<TKey>
    where TPagedParameter : class, IPagedSortedAndFilterParameter
{
    [HttpGet]
    [Route("{id}")]
    [SwaggerOperation("获取详情")]
    public virtual async Task<TDetailsResult> GetAsync([SwaggerParameter("主键ID")]TKey id)
        => await CurrentService.GetAsync(id);

    [HttpGet]
    [Route("by/no/{no}")]
    [SwaggerOperation("获取详情")]
    public virtual async Task<TDetailsResult> GetAsync(string no)
        => await CurrentService.GetAsync(no);

    [HttpPost]
    [Route("page")]
    [SwaggerOperation("获取分页列表数据")]
    public virtual async Task<PagedResultDto<TPagingListResult>> GetListAsync(TPagedParameter input)
        => await CurrentService.GetListAsync(input);

    [HttpPost]
    [Route("export")]
    [SwaggerOperation("导出")]
    public virtual async Task<FileResult> ExportAsync(TPagedParameter input)
    {
        var (bytes, fileName) = await CurrentService.ExportAsync(input);
        return ExportAsync(bytes, fileName);
    }

    [HttpGet]
    [Route("name-values")]
    [SwaggerOperation("获取下拉字典数据，Id-Name")]
    public virtual async Task<List<NameValue<TKey>>> GetNameValuesAsync([SwaggerParameter("过滤条件")][FromQuery] string filter = null)
        => await CurrentService.GetNameValuesAsync(filter);

    [HttpGet]
    [Route("name-nos")]
    [SwaggerOperation("获取下拉字典数据，No-Name")]
    public virtual async Task<List<NameValue>> GetNameNosAsync([SwaggerParameter("过滤条件")][FromQuery] string filter = null)
        => await CurrentService.GetNameNosAsync(filter);

    Task<(byte[], string)> IXmsReadOnlyAppService<TDetailsResult, TPagingListResult, TExportResult, TKey, TPagedParameter>.ExportAsync(TPagedParameter input)
    {
        throw new System.NotImplementedException();
    }
}

